package com.org.api.support.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @Description
 * @auther dh
 * @date 2021/12/28 19:30
 */
@Configuration
public class SwaggerConfig {

	@Value("${config.evn}")
	private String evn;

	@Bean
	public Docket createRestApi() {
		if (null != evn && evn.equals("dev")) {
			return new Docket(DocumentationType.OAS_30)
					.apiInfo(apiInfo())
					.select()
					.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
					.paths(PathSelectors.any())
					.build();
		}
		return new Docket(DocumentationType.OAS_30)
				.apiInfo(apiInfo())
				.select()
				.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
				.paths(PathSelectors.none())
				.build();
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder()
				.title("SHOP-API")
				.description("")
				.version("v1.0")
				.build();
	}
}
